<?php
namespace app\admin\controller;


use app\admin\model\Article;

class Index extends Backend
{
    public function index()
    {
//        $model =new Article();
//        $data =[
//            "articleid"=>1,
//            "title"=> time(),
//            "views"=>3
//        ];
//        $re = $model->editDateWithLock($data,'','views');dump($re);
        return $this->fetch();
    }
    //验证码功能 登录
    public function login(){
        if ($this->request->isPost()) {
            $param = [
                'name' => 'username',
                'password'=>'password',
            ];
            $param_data = $this->buildParam($param);//dump($param_data);exit();
            $param_data['uuid']=1;
            $param_data['role_id']=1;
            $check_login['data'] =$param_data;
            $check_login['code']=1001;
            //$check_login = $this->doModelAction($param_data, '', 'admin/user', 'checkLogin');
            //dump($check_login);exit(); //记录错误信息
            //if (!isset($check_login['code'])) $this->showReturnCodeWithSaveLog(1111);
            if ($check_login['code'] == 1001) {
                //设置全局登录
                $this->setLoginGlobal($check_login['data'], 1);
                $this->success('登陆成功！','admin/index/index','',1);
            }else{
                $this->error($check_login['msg'],'admin/index/login','',1);
            }
        }
        if($this->request->isAjax()){
            $param = [
                'name' => 'username',
                'password'=>'password',
            ];
            $param_data = $this->buildParam($param);//dump($param_data);exit();
            $param_data['uuid']=1;
            $param_data['role_id']=1;
            $check_login['data'] =$param_data;
            $check_login['code']=1001;
            //$check_login = $this->doModelAction($param_data, '', 'admin/user', 'checkLogin');
            //dump($check_login);exit(); //记录错误信息
            //if (!isset($check_login['code'])) $this->showReturnCodeWithSaveLog(1111);
            if ($check_login['code'] == 1001) {
                //设置全局登录
                $this->setLoginGlobal($check_login['data'], 1);
                $this->success('登陆成功！','admin/index/index','',1);
            }else{
                $this->error($check_login['msg'],'admin/index/login','',1);
            }
        }
        return $this->fetch();
    }

    public function logout()
    {
        $this->logoutGlobal();
        $this->redirect('index');
    }

    public function aaa()
    {
        return 'aaa';
    }

}
